﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_SaveSermonSeries')
BEGIN
    PRINT 'Dropping Procedure proc_cm_SaveSermonSeries'
    DROP  Procedure  proc_cm_SaveSermonSeries
END
GO

PRINT 'Creating Procedure proc_cm_SaveSermonSeries'
GO

CREATE PROCEDURE [dbo].[proc_cm_SaveSermonSeries]
	@pSermonSeriesId [uniqueidentifier]
	, @pSeriesNm [nvarchar](255)
	, @pDetailTxt [nvarchar](max) = null
	, @pSeriesImageUrl [varchar](100) = null
AS
BEGIN
	SET NOCOUNT ON
	
	UPDATE
		[dbo].[tbl_sermon_series]
	SET
		[series_nm] = @pSeriesNm
		,[series_image_url] = @pSeriesImageUrl
		,[detail_txt] = @pDetailTxt
	WHERE 
		[sermon_series_id] = @pSermonSeriesId
		
	IF @@ROWCOUNT = 0
	BEGIN
		INSERT INTO [dbo].[tbl_sermon_series]
		(
			[sermon_series_id]
			,[series_nm]
			,[series_image_url]
			,[detail_txt]
		)
		VALUES
		(
			@pSermonSeriesId
			,@pSeriesNm
			,@pSeriesImageUrl
			,@pDetailTxt
		)
	END
END
GO

GRANT EXEC ON dbo.proc_cm_SaveSermonSeries TO PUBLIC
GO

